package com.csdj.driverschoolsystem.controller;

import com.csdj.driverschoolsystem.common.WebResult;
import com.csdj.driverschoolsystem.entity.DriverSchool;
import com.csdj.driverschoolsystem.service.IDriverSchoolService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class DriverSchoolController {
    @Resource
    private IDriverSchoolService iDriverSchoolService;

    @ResponseBody
    @GetMapping("selDs")
    public WebResult selDs(@RequestParam(value = "cityAreaId",required = false) Integer cityAreaId,
                           @RequestParam(required = true,defaultValue = "1") Integer page){
        PageHelper.startPage(page,2);
        List<DriverSchool> listDs = iDriverSchoolService.selDs();
        PageInfo<DriverSchool> p=new PageInfo<>(listDs);
        WebResult webResult = new WebResult();
        webResult.putData("listDs",listDs).putData("p",p);
        return webResult;
    }



    @ResponseBody
    @GetMapping("selDsId")
    public WebResult selDsId(@RequestParam(value = "id",required = true) Integer id){
        DriverSchool driverSchool = iDriverSchoolService.selDsId(id);
        WebResult webResult = new WebResult();
        webResult.putData("driverSchool",driverSchool);
        return webResult;
    }
}
